package com.wx.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.wx.dao.UserInfoDao;
import com.wx.model.Users;
import com.wx.util.DBUtil;

public class UserInfoDaoImpl implements UserInfoDao {

	@Override
	public void modifyUserInfo(Users user) throws Exception {
		Connection conn = DBUtil.getConnection();
		PreparedStatement ps = conn.prepareStatement("update users(truename,gender,phone,home,postcode) values(?,?,?,?,?) where username=?");
		ps.setString(1, user.getTruename());
		ps.setString(2, user.getGender());
		ps.setString(3, user.getPhone());
		ps.setString(4, user.getHome());
		ps.setInt(5, user.getPostcode());
		ps.setString(6, user.getUsername());
		ps.executeUpdate();
		
		ps.close();
		conn.close();
	}

	@Override
	public boolean findAddress(String username) throws Exception {
		boolean b=true;
		Connection conn = DBUtil.getConnection();
		PreparedStatement ps = conn.prepareStatement("select home from users where username=?");
		ps.setString(1,username);
		ResultSet rs = ps.executeQuery();
		if(rs.next()){
			String home = rs.getString(1);
			if(home==""){
				b=false;
			}
		}
		System.out.println(b);
		return b;
	}

}
